﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using SelfService.Model.Models;
using SelfService.Model;
using SelfService.Model.ViewModels;


namespace SelfService.ViewModel.SysPatientVMs
{
    public partial class SysPatientListVM : BasePagedListVM<SysPatient_View, SysPatientSearcher>
    {

        protected override IEnumerable<IGridColumn<SysPatient_View>> InitGridHeader()
        {
            return new List<GridColumn<SysPatient_View>>{
                this.MakeGridHeader(x => x.CardNo),
                this.MakeGridHeader(x => x.Name),
                this.MakeGridHeader(x => x.Age),
                this.MakeGridHeader(x => x.Sex),
                this.MakeGridHeader(x => x.Balance),
                this.MakeGridHeader(x => x.IdCardNo),
                this.MakeGridHeader(x => x.IcCardNo),
                this.MakeGridHeader(x => x.Uid),
                this.MakeGridHeader(x => x.Address),
                this.MakeGridHeader(x => x.Phone),
                this.MakeGridHeader(x => x.LastTime),
                this.MakeGridHeader(x => x.CreateTime),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<SysPatient_View> GetSearchQuery()
        {
            var query = DC.Set<SysPatient>()
                .CheckContain(Searcher.CardNo, x=>x.CardNo)
                .CheckContain(Searcher.Name, x=>x.Name)
                .CheckEqual(Searcher.Age, x=>x.Age)
                .CheckEqual(Searcher.Sex, x=>x.Sex)
                .CheckContain(Searcher.IdCardNo, x=>x.IdCardNo)
                .CheckContain(Searcher.IcCardNo, x=>x.IcCardNo)
                .CheckContain(Searcher.Uid, x=>x.Uid)
                .CheckContain(Searcher.Address, x=>x.Address)
                .CheckContain(Searcher.Phone, x=>x.Phone)
                .CheckBetween(Searcher.LastTime?.GetStartTime(), Searcher.LastTime?.GetEndTime(), x => x.LastTime, includeMax: false)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .Select(x => new SysPatient_View
                {
				    ID = x.ID,
                    CardNo = x.CardNo,
                    Name = x.Name,
                    Age = x.Age,
                    Sex = x.Sex,
                    Balance = x.Balance,
                    IdCardNo = x.IdCardNo,
                    IcCardNo = x.IcCardNo,
                    Uid = x.Uid,
                    Address = x.Address,
                    Phone = x.Phone,
                    LastTime = x.LastTime,
                    CreateTime = x.CreateTime,
                })
                .OrderBy(x => x.ID);
            return query;
        }

    }

    public class SysPatient_View : SysPatient{

    }
}
